﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Kernel
{
    public class UserControlEx:UserControl,IControlEx
    {
        public UserControlEx()
        {
            InitializeComponent();

            ControlExList = new List<IControlEx>();
        }

        public List<IControlEx> ControlExList { get; set; }

        #region 实现IControlEx接口
        void IControlEx.Init() { UI_Init(); }
        void IControlEx.Load() { UI_Load(); }
        void IControlEx.Update() { UI_Update(); }
        void IControlEx.Save() { UI_Save(); }
        bool IControlEx.Updated { get { return UI_Updated; } }
        #endregion

        protected bool UI_Updated;

        protected virtual void UI_Init()
        { }

        protected virtual void UI_Load()
        { }

        protected virtual void UI_Update()
        { }

        protected virtual void UI_Save()
        { }

        //public static List<IControlEx> _lst_ctl_ex = new List<IControlEx>();

        public void AddExControl( IControlEx item )
        {
            this.ControlExList.Add(item);
        }
        /// <summary>
        /// 初始化全部实现IControlEx接口的控件
        /// </summary>
        public void InitAllExControls()
        {
            foreach (IControlEx ui in ControlExList)
                ui.Init();
        }

        /// <summary>
        /// 加载全部实现IControlEx接口的控件(这里放那些只需要加载一次的控件)
        /// </summary>
        public void LoadAllExControls()
        {
            foreach (IControlEx ui in ControlExList)
                ui.Load();
        }

        /// <summary>
        /// 更新全部实现IControlEx接口的控件(这里放那些需要多次刷新的控件)
        /// </summary>
        public void UpdateAllExControls()
        {
            foreach (IControlEx ui in ControlExList)
                ui.Update();
        }

        /// <summary>
        /// 保存全部实现IControlEx接口的控件(这里放那些需要多次刷新的控件)
        /// </summary>
        public void SaveAllExControls()
        {
            foreach (IControlEx ui in ControlExList)
                ui.Save();
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // UserControlEx
            // 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
            this.Dock = DockStyle.Fill;
            this.Name = "UserControlEx";
            this.ResumeLayout(false);

        }
    }
}
